package com.ruoyi.web.controller.video;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.video.domain.TeacherInfo;
import com.ruoyi.video.domain.VideoInfo;
import com.ruoyi.video.service.TeacherInfoService;
import com.ruoyi.video.service.VideoInfoService;
import com.ruoyi.web.core.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 视频 信息操作处理
 *
 * @author pig13
 * @date 2018-11-11
 */
@Controller
@RequestMapping("/video/videoInfo")
public class VideoInfoController extends BaseController {
    private String prefix = "video/videoInfo";

    @Autowired
    private VideoInfoService videoInfoService;
    @Autowired
    private TeacherInfoService teacherInfoService;

    @RequiresPermissions("video:videoInfo:view")
    @GetMapping()
    public String videoInfo() {
        return prefix + "/videoInfo";
    }

    /**
     * 查询视频列表
     */
    @RequiresPermissions("video:videoInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VideoInfo videoInfo) {
        startPage();
        List<VideoInfo> list = videoInfoService.selectVideoInfoList(videoInfo);
        return getDataTable(list);
    }

    /**
     * 新增视频
     */
    @GetMapping("/add")
    public String add(Model model) {
        List<TeacherInfo> teacherInfos = teacherInfoService.selectTeacherInfoBriefList("");
        model.addAttribute("teacherInfos", teacherInfos);
        return prefix + "/add";
    }

    /**
     * 新增保存视频
     */
    @RequiresPermissions("video:videoInfo:add")
    @Log(title = "视频", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VideoInfo videoInfo) {
        return toAjax(videoInfoService.insertVideoInfo(videoInfo));
    }

    /**
     * 修改视频
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        VideoInfo videoInfo = videoInfoService.selectVideoInfoById(id);
        mmap.put("videoInfo", videoInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频
     */
    @RequiresPermissions("video:videoInfo:edit")
    @Log(title = "视频", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VideoInfo videoInfo) {
        return toAjax(videoInfoService.updateVideoInfo(videoInfo));
    }

    /**
     * 删除视频
     */
    @RequiresPermissions("video:videoInfo:remove")
    @Log(title = "视频", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(videoInfoService.deleteVideoInfoByIds(ids));
    }

}
